home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / plugins / maphalflifeentitylines.py < prev    next >
Text File  |  2004-01-05  |  19KB  |  310 lines

  1. """   QuArK  -  Quake Army Knife
  2.  
  3. History:
  4. 1999-12-23  Added func_tracktrain wheeldistance, but only X-axis
  5. 1999-12-21  Added func_tank* barrel-position-lines (BTW: I hate Python's way of indenting, without the need for begin/end's)
  6. 1999-??-??  Added Team Fortress Classic stuff..
  7. 1999-02-20  Added <entity>:TriggerTarget -> <entity>:targetname
  8. 1999-02-12  Added scripted_sequence:m_iszEntity -> <entity>:targetname
  9. 1999-01-24  Added trigger_changelevel -> info_landmark
  10. 1999-01-16  Added axis-rotating lines to rotating entities, so its a little easier to visualize around what the entity will rotate.
  11. """
  12.  
  13.  
  14. #$Header: /cvsroot/quark/runtime/plugins/maphalflifeentitylines.py,v 1.4 2001/02/13 21:02:55 decker_dk Exp $
  15.  
  16.  
  17. Info = {
  18.    "plug-in":       "Half-Life Arrow Extensions",
  19.    "desc":          "Arrows/Axis for specifics like: 'master', 'multi_manager' and more...",
  20.    "date":          "23 dec 99",
  21.    "author":        "Decker",
  22.    "author e-mail": "decker@post1.tele.dk",
  23.    "quark":         "Version 5.10" }
  24.  
  25.  
  26. from quarkpy.maputils import *
  27. import quarkpy.mapentities
  28. from quarkpy.qeditor import MapColor
  29.  
  30. DefaultDrawEntityLines = quarkpy.mapentities.DefaultDrawEntityLines
  31. quakecolor = quarkpy.mapentities.quakecolor
  32. makeRGBcolor = quarkpy.mapentities.makeRGBcolor
  33. ObjectOrigin = quarkpy.mapentities.ObjectOrigin
  34.  
  35. import plugins.deckerutils
  36. FindOriginTexPolyPos = plugins.deckerutils.FindOriginTexPolyPos
  37.  
  38. class HalfLifeDrawEntityLines(DefaultDrawEntityLines):
  39.  
  40.     def showoriginline(self, entity, xaxisbitvalue, yaxisbitvalue, view, color):
  41.         orgpos = FindOriginTexPolyPos(entity)
  42.         if orgpos is not None:
  43.             try:
  44.                 axisflags = int(entity["spawnflags"])
  45.             except:
  46.                 axisflags = 0
  47.             axisdist = quarkx.vect(0,0,0)
  48.             if axisflags & xaxisbitvalue:
  49.                 axisdist = quarkx.vect(16,0,0) # 16 is just some appropriate value I choosed
  50.             elif axisflags & yaxisbitvalue:
  51.                 axisdist = quarkx.vect(0,16,0)
  52.             else:
  53.                 axisdist = quarkx.vect(0,0,16)
  54.             cv = view.canvas()
  55.             cv.pencolor = color
  56.             cv.penwidth = 3 # So it the axis gets more visual
  57.             pos1, pos2 = (orgpos + axisdist), (orgpos - axisdist)
  58.             vpos1, vpos2 = view.proj(pos1), view.proj(pos2)
  59.             cv.line(vpos1, vpos2)
  60.         return orgpos
  61.  
  62.     def drawentitylines(self, entity, org, view, entities, processentities):
  63.         # Draw the default target/targetname/killtarget/light/_light arrows/ellipse
  64.         DefaultDrawEntityLines.drawentitylines(self, entity, org, view, entities, processentities)
  65.         # From here its Half-Life special
  66.         axiscolor = MapColor("Axis")
  67.         stopcolor = 0x808080    # (grey) when firing an Stop/End/Close action
  68.         passcolor = 0x0080ff    # (orange) when firing an Pass-this-point action
  69.         branchcolor = 0xff8000  # (blue) alternate path-route
  70.         mastercolor = 0x00af00  # (green) points to a multisource/train entity
  71.         rotcolor = 0xff00ff # (magenta) rotation axis
  72.         org1 = view.proj(org)
  73.         if org1.visible:
  74.             R1 = entity["radius"] # For env_sound:e
  75.             R2 = entity["m_flRadius"] # For scripted_sequence:e
  76.     # TFC - Begin
  77.             R3 = entity["t_length"] # for info_tfgoal
  78.     # TFC - End
  79.             if R1 or R2 or R3:
  80.                 try:
  81.                     if R1:
  82.                         radius = float(R1) * view.scale(org)
  83.                     elif R2:
  84.                         radius = float(R2) * view.scale(org)
  85.                     else:
  86.                         radius = float(R3) * view.scale(org)
  87.                     cv = view.canvas()
  88.                     cv.pencolor = axiscolor
  89.                     cv.brushcolor = axiscolor
  90.                     cv.penwidth = 1
  91.                     cv.brushstyle = BS_BDIAGONAL
  92.                     cv.ellipse(org1.x-radius, org1.y-radius, org1.x+radius, org1.y+radius)
  93.                 except:
  94.                     pass
  95.             if entity.name in ["func_door_rotating:b","func_platrot:b","func_rotating:b","func_rot_button:b","func_pendulum:b","func_trackautochange:b","func_trackchange:b","momentary_rot_button:b"]:
  96.                 if entity.name == "func_rotating:b":
  97.                     self.showoriginline(entity,4,8,view,rotcolor) # func_rotating has different bitvalues for X-axis and Y-axis
  98.                 else:
  99.                     self.showoriginline(entity,64,128,view,rotcolor)
  100.             elif entity.name in ["func_tank:b","func_tanklaser:b","func_tankmortar:b","func_tankrocket:b"]:
  101.                 orgpos = self.showoriginline(entity,0,0,view,rotcolor) # Tanks always rotate around Z-axis
  102.                 # I need an canvas.arc() drawing-function so I can display the yaw/pitch range of the tank.
  103.                 if orgpos is not None:
  104.                     try:
  105.                         by = int(entity["barrely"])
  106.                     except:
  107.                         by = 0
  108.                     try:
  109.                         bz = int(entity["barrelz"])
  110.                     except:
  111.                         bz = 0
  112.                     try:
  113.                         bx = int(entity["barrel"])
  114.                     except:
  115.                         bx = 0
  116.                     try:
  117.                         brly = orgpos + quarkx.vect(0, by, 0)
  118.                         brlz = brly + quarkx.vect(0, 0, bz)
  119.                         brlx = brlz + quarkx.vect(bx, 0, 0)
  120.                         cv = view.canvas()
  121.                         cv.pencolor = passcolor
  122.                         cv.penwidth = 3 # So it the barrel pos gets more visual
  123.                         vpos1, vpos2 = view.proj(orgpos), view.proj(brly)
  124.                         cv.line(vpos1, vpos2)
  125.                         vpos1, vpos2 = view.proj(brly), view.proj(brlz)
  126.                         cv.line(vpos1, vpos2)
  127.                         vpos1, vpos2 = view.proj(brlz), view.proj(brlx)
  128.                         cv.line(vpos1, vpos2)
  129.                     except:
  130.                         pass
  131.             elif entity.name == "func_tracktrain:b":
  132.                 orgpos = self.showoriginline(entity,0,0,view,rotcolor) # TrackTrain always rotate around Z-axis
  133.                 if orgpos is not None:
  134.                     try:
  135.                         wheelsdist = int(entity["wheels"]) / 2
  136.                     except:
  137.                         wheeldist = 0
  138.                     try:
  139.                         heightdist = int(entity["height"])
  140.                     except:
  141.                         heightdist = 0
  142.                     try:
  143.                         heit = orgpos - quarkx.vect(0, 0, heightdist)
  144.                         whlxA = heit - quarkx.vect(0, wheelsdist, 0)
  145.                         whlxB = heit + quarkx.vect(0, wheelsdist, 0)
  146.                         whlAyA = whlxA - quarkx.vect(16,0,0)
  147.                         whlAyB = whlxA + quarkx.vect(16,0,0)
  148.                         whlByA = whlxB - quarkx.vect(16,0,0)
  149.                         whlByB = whlxB + quarkx.vect(16,0,0)
  150.                         cv = view.canvas()
  151.                         cv.pencolor = 0x000000
  152.                         cv.penwidth = 3 # So it the wheeldist gets more visual
  153.                         vpos1, vpos2 = view.proj(orgpos), view.proj(heit)
  154.                         cv.line(vpos1, vpos2)
  155.                         vpos1, vpos2 = view.proj(whlxA), view.proj(whlxB)
  156.                         cv.line(vpos1, vpos2)
  157.                         vpos1, vpos2 = view.proj(whlAyA), view.proj(whlAyB)
  158.                         cv.line(vpos1, vpos2)
  159.                         vpos1, vpos2 = view.proj(whlByA), view.proj(whlByB)
  160.                         cv.line(vpos1, vpos2)
  161.                     except:
  162.                         pass
  163.  
  164.     # TFC - Begin
  165.         if entity["group_no"] is not None:
  166.             DefaultDrawEntityLines.drawentityarrows(self, "group_no", entity["group_no"], org, -1, 0x010101, view, entities, processentities)
  167.  
  168.         if entity["items"] is not None:
  169.             DefaultDrawEntityLines.drawentityarrows(self, "goal_no", entity["items"], org, -1, 0xFF88FF, view, entities, processentities)
  170.  
  171.         if entity["items_allowed"] is not None:
  172.             DefaultDrawEntityLines.drawentityarrows(self, "goal_no", entity["items_allowed"], org, 1, 0xFFFFFF, view, entities, processentities)
  173.         if entity["has_item_from_group"] is not None:
  174.             DefaultDrawEntityLines.drawentityarrows(self, "group_no", entity["has_item_from_group"], org, -1, 0xCCCCCC, view, entities, processentities)
  175.         if entity["if_goal_is_active"] is not None:
  176.             DefaultDrawEntityLines.drawentityarrows(self, "goal_no", entity["if_goal_is_active"], org, -1, 0xFFFFFF, view, entities, processentities)
  177.  
  178.         if entity["axhitme"] is not None:
  179.             DefaultDrawEntityLines.drawentityarrows(self, "goal_no", entity["axhitme"], org, 0, 0xFF8888, view, entities, processentities)
  180.         if entity["restore_goal_no"] is not None:
  181.             DefaultDrawEntityLines.drawentityarrows(self, "goal_no", entity["restore_goal_no"], org, 0, 0x88FF88, view, entities, processentities)
  182.         if entity["impulse"] is not None:
  183.             DefaultDrawEntityLines.drawentityarrows(self, "goal_no", entity["impulse"], org, 0, 0x88FF88, view, entities, processentities)
  184.         if entity["remove_goal_no"] is not None:
  185.             DefaultDrawEntityLines.drawentityarrows(self, "goal_no", entity["remove_goal_no"], org, 0, 0x88FF88, view, entities, processentities)
  186.  
  187.         if entity["activate_group_no"] is not None:
  188.             DefaultDrawEntityLines.drawentityarrows(self, "group_no", entity["activate_group_no"], org, 0, 0x0088CC, view, entities, processentities)
  189.     # TFC - End
  190.  
  191.         etargetname = entity["targetname"]
  192.         if etargetname is not None:
  193.             DefaultDrawEntityLines.drawentityarrows(self, "master", etargetname, org, 1, mastercolor, view, entities, processentities)
  194.             # Must insert arrows from other entities with special specific-names also!
  195.             for i in entities:
  196.                 if i.name == "multi_manager:e":
  197.                     if i[etargetname] is not None: # Does multi_manager has a specific that matches out targetname-value?
  198.                         DefaultDrawEntityLines.drawentityarrow(self, i, org, 1, axiscolor, view, processentities) # DECKER - Maybe add a text ("time "+i[etargetname])
  199.                 elif i["netname"] == etargetname:
  200.                     if i.name  == "func_door:b":    # func_door.netname -> fire on close
  201.                         DefaultDrawEntityLines.drawentityarrow(self, i, org, 1, stopcolor, view, processentities, "Fire on Close")
  202.                     elif i.name == "func_button:b": # func_button.netname -> target path
  203.                         DefaultDrawEntityLines.drawentityarrow(self, i, org, 1, axiscolor, view, processentities, "Target Path")
  204.                     elif i.name == "path_track:e":  # path_track.netname -> fire on dead end
  205.                         DefaultDrawEntityLines.drawentityarrow(self, i, org, 1, stopcolor, view, processentities, "Fire on Dead End")
  206.                     elif i.name == "monster_bigmomma:e": # monster_bigmomma.netname -> first node
  207.                         DefaultDrawEntityLines.drawentityarrow(self, i, org, 1, axiscolor, view, processentities)
  208.                 elif i.name in ["path_corner:e", "path_track:e"]:
  209.                     if i["message"] == etargetname: # path_*.message -> fire on pass
  210.                         DefaultDrawEntityLines.drawentityarrow(self, i, org, 1, passcolor, view, processentities, "Fire on Pass")
  211.                     if i["altpath"] == etargetname: # path_track.altpath -> branch path
  212.                         DefaultDrawEntityLines.drawentityarrow(self, i, org, 1, branchcolor, view, processentities, "Branch Path")
  213.                 elif i.name == "func_trackchange:b":
  214.                     if i["train"] == etargetname:
  215.                         DefaultDrawEntityLines.drawentityarrow(self, i, org, 1, mastercolor, view, processentities, "Train")
  216.                     if i["toptrack"] == etargetname:
  217.                         DefaultDrawEntityLines.drawentityarrow(self, i, org, 1, axiscolor, view, processentities, "Top Track")
  218.                     if i["bottomtrack"] == etargetname:
  219.                         DefaultDrawEntityLines.drawentityarrow(self, i, org, 1, branchcolor, view, processentities, "Bottom Track")
  220.                 elif i.name == "func_guntarget:b":
  221.                     if i["message"] == etargetname: # path_*.message -> fire on damage
  222.                         DefaultDrawEntityLines.drawentityarrow(self, i, org, 1, passcolor, view, processentities, "Fire on damage")
  223.                 elif i.name == "env_beam:e":
  224.                     if i["LightningStart"] == etargetname:
  225.                         DefaultDrawEntityLines.drawentityarrow(self, i, org, 1, axiscolor, view, processentities, "LightingStart")
  226.                     if i["LightningEnd"] == etargetname:
  227.                         DefaultDrawEntityLines.drawentityarrow(self, i, org, 1, axiscolor, view, processentities, "LightingEnd")
  228.                 elif i.name == "trigger_changelevel:b":
  229.                     if i["landmark"] == etargetname:
  230.                         DefaultDrawEntityLines.drawentityarrow(self, i, org, 1, axiscolor, view, processentities, "Landmark")
  231.                 elif i.name == "scripted_sequence:e":
  232.                     if i["m_iszEntity"] == etargetname:
  233.                         DefaultDrawEntityLines.drawentityarrow(self, i, org, 1, axiscolor, view, processentities, "Scripted Sequence")
  234.                 elif i["TriggerTarget"] == etargetname:
  235.                     DefaultDrawEntityLines.drawentityarrow(self, i, org, 1, branchcolor, view, processentities, "TriggerTarget")
  236.  
  237.         if entity["master"] is not None:
  238.             DefaultDrawEntityLines.drawentityarrows(self, "targetname", entity["master"], org, 0, mastercolor, view, entities, processentities)
  239.         if entity["netname"] is not None:
  240.             if entity.name == "func_door:b":
  241.                 DefaultDrawEntityLines.drawentityarrows(self, "targetname", entity["netname"], org, 0, stopcolor, view, entities, processentities, "Fire on Close")
  242.             elif entity.name == "func_button:b":
  243.                 DefaultDrawEntityLines.drawentityarrows(self, "targetname", entity["netname"], org, 0, axiscolor, view, entities, processentities, "Target Path")
  244.             elif entity.name == "path_track:e":
  245.                 DefaultDrawEntityLines.drawentityarrows(self, "targetname", entity["netname"], org, 0, stopcolor, view, entities, processentities, "Fire on Dead End")
  246.             elif entity.name == "monster_bigmomma:e":
  247.                 DefaultDrawEntityLines.drawentityarrows(self, "targetname", entity["netname"], org, 0, axiscolor, view, entities, processentities)
  248.         if entity["TriggerTarget"] is not None:
  249.             DefaultDrawEntityLines.drawentityarrows(self, "targetname", entity["TriggerTarget"], org, 0, branchcolor, view, entities, processentities, "TriggerTarget")
  250.         # -- From here, its an if-elif structure --
  251.         if entity.name == "multi_manager:e":
  252.             # Targets is in specifics, must extract them and make arrows
  253.             for i in entity.dictspec.keys():
  254.                 if i not in ["targetname", "origin"]: # Ignore the two known specifics
  255.                     DefaultDrawEntityLines.drawentityarrows(self, "targetname", i, org, 0, axiscolor, view, entities, processentities) # DECKER - Maybe add a text ("time "+entity[i])
  256.         elif entity.name == "path_corner:e":
  257.             if entity["message"] is not None:
  258.                 DefaultDrawEntityLines.drawentityarrows(self, "targetname", entity["message"], org, 0, passcolor, view, entities, processentities, "Fire on Pass")
  259.         elif entity.name == "path_track:e":
  260.             if entity["message"] is not None:
  261.                 DefaultDrawEntityLines.drawentityarrows(self, "targetname", entity["message"], org, 0, passcolor, view, entities, processentities, "Fire on Pass")
  262.             if entity["altpath"] is not None:
  263.                 DefaultDrawEntityLines.drawentityarrows(self, "targetname", entity["altpath"], org, 0, branchcolor, view, entities, processentities, "Branch Path")
  264.         elif entity.name == "func_trackchange:b":
  265.             if entity["train"] is not None:
  266.                 DefaultDrawEntityLines.drawentityarrows(self, "targetname", entity["train"], org, 0, mastercolor, view, entities, processentities, "Train")
  267.             if entity["toptrack"] is not None:
  268.                 DefaultDrawEntityLines.drawentityarrows(self, "targetname", entity["toptrack"], org, 0, axiscolor, view, entities, processentities, "Top Track")
  269.             if entity["bottomtrack"] is not None:
  270.                 DefaultDrawEntityLines.drawentityarrows(self, "targetname", entity["bottomtrack"], org, 0, branchcolor, view, entities, processentities, "Bottom Track")
  271.         elif entity.name == "func_guntarget:b":
  272.             if entity["message"] is not None:
  273.                 DefaultDrawEntityLines.drawentityarrows(self, "targetname", entity["message"], org, 0, passcolor, view, entities, processentities, "Fire on Damage")
  274.         elif entity.name == "env_beam:e":
  275.             if entity["LightningStart"] is not None:
  276.                 DefaultDrawEntityLines.drawentityarrows(self, "targetname", entity["LightningStart"], org, 0, axiscolor, view, entities, processentities, "LightningStart")
  277.             if entity["LightningEnd"] is not None:
  278.                 DefaultDrawEntityLines.drawentityarrows(self, "targetname", entity["LightningEnd"], org, 0, axiscolor, view, entities, processentities, "LightningEnd")
  279.         elif entity.name == "trigger_changelevel:b":
  280.             if entity["landmark"] is not None:
  281.                 DefaultDrawEntityLines.drawentityarrows(self, "targetname", entity["landmark"], org, 0, axiscolor, view, entities, processentities, "Landmark")
  282.         elif entity.name == "scripted_sequence:e":
  283.             if entity["m_iszEntity"] is not None:
  284.                 DefaultDrawEntityLines.drawentityarrows(self, "targetname", entity["m_iszEntity"], org, 0, axiscolor, view, entities, processentities, "Scripted Sequence")
  285.         elif entity.name == "multisource:e":
  286.             # 'globalstate' points to an env_global entity which must have the same 'globalstate'
  287.             pass # DECKER - Going to implement later
  288.  
  289.  
  290. #
  291. # Register this class with its gamename
  292. #
  293. quarkpy.mapentities.EntityLinesMapping.update({
  294.   "Half-Life": HalfLifeDrawEntityLines()
  295. })
  296.  
  297.  
  298. # ----------- REVISION HISTORY ------------
  299. #
  300. #
  301. # $Log: maphalflifeentitylines.py,v $
  302. # Revision 1.4  2001/02/13 21:02:55  decker_dk
  303. # Tabbing problem, which is a really serious problem with Python!!
  304. #
  305. # Revision 1.3  2000/06/03 10:25:30  alexander
  306. # added cvs headers
  307. #
  308. #
  309. #
  310. #